package service

import (
	"singo/model"
	"singo/serializer"
)

// DefectDeleteService 删除缺陷的服务
type DefectDeleteService struct {
}

// DefectDelete 删除缺陷
func (service *DefectDeleteService) DefectDelete(uid string) serializer.Response {
	var defect model.Defect
	err := model.DB.First(&defect, "uid = ?", uid).Error
	if err != nil {
		return serializer.Response{
			Status: 404,
			Msg:    "缺陷不存在",
			Error:  err.Error(),
		}
	}

	err = model.DB.Delete(&defect).Error
	if err != nil {
		return serializer.Response{
			Status: 50000,
			Msg:    "缺陷删除失败",
			Error:  err.Error(),
		}
	}

	return serializer.Response{
		Data:   true,
		Msg:    "成功",
		Status: 0,
	}
}
